package co.com.tigo.crm.v1.portalcrmservice.builder;

import java.util.List;

import co.com.colombiamovil.gatewayservice.facade.dto.ServiceEnableDisableDTO;
import co.com.colombiamovil.gatewayservice.facade.exception.GatewayServiceFacadeException;
import co.com.millicom.utilcommons.dto.ResponseService;
import co.com.tigo.crm.v1.portalcrmservice.Fault;
import co.com.tigo.xmlns.crm.AvailableService;
import co.com.tigo.xmlns.crm.AvailableServicesTypes;
import co.com.tigo.xmlns.crm.commons.FaultMessageType;
import co.com.tigo.xmlns.crm.commons.GeneralResponseType;
import co.com.tigo.xmlns.crm.commons.SeverityType;

public class XSDBuilder {

	public static AvailableServicesTypes toAvailableServicesResponse(List<ServiceEnableDisableDTO> lisDisableDTOs) {
		AvailableServicesTypes availableServicesResponse = new AvailableServicesTypes();
		availableServicesResponse.setServiceTypeList(new AvailableServicesTypes.ServiceTypeList() );
		 
		for (ServiceEnableDisableDTO serviceEnableDisableDTO : lisDisableDTOs) {
			AvailableService availableServiceType = new AvailableService();
			availableServiceType.setActive(serviceEnableDisableDTO.isActive());
			availableServiceType.setName( serviceEnableDisableDTO.getService().getServiceName());
			availableServiceType.setServiceDescription(serviceEnableDisableDTO.getService().getServiceDescription());
			availableServiceType.setServiceId(serviceEnableDisableDTO.getService().getServiceId());
			availableServicesResponse.getServiceTypeList().getServiceType().add(availableServiceType);
		}
		return availableServicesResponse;
	}

	public static Fault toFault(GatewayServiceFacadeException e) {
		FaultMessageType faultInfo = new FaultMessageType();
		faultInfo.setCode(e.getCode());
		faultInfo.setDescription(e.getDescription());
		switch (e.getSeverity()) {
		case INFO:
			faultInfo.setSeverity(SeverityType.INFO);
			break;
		default:
			faultInfo.setSeverity(SeverityType.ERROR);
		}

		Fault fault = new Fault(e.getMessage(),
				faultInfo);
		return fault;
	}
	

	public static GeneralResponseType toGeneralResponseType(ResponseService responseService) {
		GeneralResponseType generalResponseType = new GeneralResponseType();
		generalResponseType.setCode(responseService.getCode());
		generalResponseType.setDescription(responseService.getDescription());
		return generalResponseType;
	}

}
